//
//  HWxiaohaoSmallTransactionsViewController.m
//  HWanGame
//
//  Created by 陈道斌 on 2020/12/21.
//  Copyright © 2020 Chendaobin. All rights reserved.
//

#import "HWxiaohaoSmallTransactionsViewController.h"
#import "HWjiaoyiModel.h"
#import "HWjiaoyijiemianCollectionViewCell.h"
#import "HWzuixingjiaoyidanyuanTableViewCell.h" // 最新
#import "HWjiaoyuLiebiaoModel.h"



#import "HWClinchDealCell.h"
#import "HWChenjiaoDonTaiViewController.h"
#import "HWScreeningView.h" //筛选View
#import "HWSortingView.h"
#import "HWQuanBuView.h"
#import "HWJiaoyixuzhiViewController.h"
#import "HWAccountDetailsViewController.h"
#import "HWViewSellNoController.h" // 我要卖号
#import "HWCustomerServiceCenterViewController.h" // 客服中心
#import "HWTradingModel.h"
#import "HWsXiaoHaoGuanLiViewController.h"
#import "HWLoginController.h" // 登录界面
#import "HWMyTradingViewController.h" //我的交易
#import "HWTradecollectionShouCangViewController.h" //  

#import "HWXuanzePanxuView.h"

#import "XMGWebViewController.h"



@interface HWxiaohaoSmallTransactionsViewController ()<UITableViewDelegate,UITableViewDataSource,UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,UITextFieldDelegate,HWXuanzePanxuViewDelegate>


@property(strong,nonatomic)UITableView *mainaTableVie;
@property(strong,nonatomic) UIView *headerView;
@property(strong,nonatomic) UIView *beijingView;

@property(strong,nonatomic) UIView *guangFanjingxunaView;
@property(strong,nonatomic) UICollectionView *maincollectionView;

@property(strong,nonatomic) NSMutableArray *topMuArr;
@property(strong,nonatomic) NSMutableArray *listMuArr;
@property(strong,nonatomic) NSString *p;
@property(strong,nonatomic) NSString *max_p;
@property(strong,nonatomic) NSString *keyword;
@property(strong,nonatomic) NSString *sortStr;
@property(strong,nonatomic) UILabel *xianshiLabel;


@property(strong,nonatomic) UIView *sectionheaderView;

@property(strong,nonatomic) HWXuanzePanxuView *sortingView;













@end

@implementation HWxiaohaoSmallTransactionsViewController


-(HWXuanzePanxuView *)sortingView  {
    if (_sortingView ==nil) {
        _sortingView = [[HWXuanzePanxuView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
        _sortingView.backgroundColor  = [UIColor  clearColor];
        
    }
    
    return _sortingView;
    
}


-(UITableView *)mainaTableVie {
    
    if  (_mainaTableVie == nil) {
        
        //   _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, -StatusBarHeight, kScreenW, kScreenH-TabBarHeight) style:UITableViewStylePlain];
        
        _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
        _mainaTableVie.delegate = self;
        _mainaTableVie.dataSource = self;
        _mainaTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        _mainaTableVie.backgroundColor = [UIColor whiteColor];
        
        _mainaTableVie.backgroundColor =  RGB(247, 247, 247);
        _mainaTableVie.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        
        
    }
    return   _mainaTableVie ;
    
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    NSLog(@"1111111");
    
    
    
    
    [self.navigationController setNavigationBarHidden:YES];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
    NSLog(@"22222222");
    // 这个注意一点
    [self.navigationController setNavigationBarHidden:NO];
}





- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    //设置常用属性
    [self shezhichangyongshuxing];
    
    
    //  设置UI
    [self setupUI];
    
    // 发送请求数据
    //  [self fasongshujuqingqiu];
    
    
    [self addrefreshControl];
    
    
    
    
    
}


- (void)addrefreshControl {
    
    self.mainaTableVie.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(underRefresh)];
    [self.mainaTableVie.mj_header beginRefreshing];
    self.mainaTableVie.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(onRefresh)];
    
    
    
}


// 设置常用的属性
- (void)shezhichangyongshuxing {
    
    self.sortStr  = @"0";
    self.keyword = @"";
    
    
    
    
}





- (void)underRefresh {
    
    
    NSString *userID = [HWLocallyStoredData getLoginUserID];
    NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
    NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tStr,@"fsd213ewdsadqwe2121213edsad"];
    NSString *signMD5 = [WMUtil md5HexDigest:sign];
    NSDictionary *parametes = @{
        @"ct" :  @"app",
        @"ac" : @"trade",
        @"sort" : self.sortStr,
        @"system":@"0",
        @"keyword": self.keyword,
        @"member_id":[HWLocallyStoredData getCode],
        
    };
    
    
    
    //    [MBProgressHUD show:@"正在绑定邮箱"];
    
    [HWWebUtils do3GetWithParameters:parametes progress:nil success:^(id response) {
        
        
        NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
        //   [MBProgressHUD hideHUD];
        
        [self.mainaTableVie.mj_header endRefreshing];
        [self.mainaTableVie.mj_footer endRefreshing];
        
        
        if ([codeStr intValue] == 1) {
            
            
            self.topMuArr = [HWjiaoyiModel mj_objectArrayWithKeyValuesArray:response[@"data"][@"top"]];
            self.listMuArr = [HWjiaoyuLiebiaoModel mj_objectArrayWithKeyValuesArray:response[@"data"][@"list"]];
            
            self.p = [NSString stringWithFormat:@"%@",response[@"data"][@"p"]];
            self.max_p =  [NSString stringWithFormat:@"%@",response[@"data"][@"max_p"]];
            
            
            [self.mainaTableVie reloadData];
            [self.maincollectionView reloadData];
            
            
            
            
        } else {
            
            [MBProgressHUD  showSuccess:response[@"message"]];
            
            [self.mainaTableVie reloadData];
            
        }
        NSLog(@"%@",response);
        
        
    } failure:^(NSString *error) {
        
        [MBProgressHUD  showError:@"查询失败"];
        
        [self.mainaTableVie.mj_header endRefreshing];
        [self.mainaTableVie.mj_footer endRefreshing];
        
        
        
    }];
    
    
    
    
    
    
}




- (void)onRefresh {
    
    
    
    if ([self.p  intValue]> [self.max_p  intValue]) {
        
        [self.mainaTableVie.mj_header endRefreshing];
        [self.mainaTableVie.mj_footer endRefreshing];
        
        [MBProgressHUD  showSuccess:@"请稍后在加载数据"];
        
        return;
    }
    
    
    
    NSString *userID = [HWLocallyStoredData getLoginUserID];
    NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
    NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tStr,@"fsd213ewdsadqwe2121213edsad"];
    NSString *signMD5 = [WMUtil md5HexDigest:sign];
    NSDictionary *parametes = @{
        @"ct" :  @"app",
        @"ac" : @"trade",
        @"sort" : self.sortStr,
        @"system":@"0",
        @"keyword": self.keyword,
        @"member_id":[HWLocallyStoredData getCode],
        
    };
    
    
    
    //    [MBProgressHUD show:@"正在绑定邮箱"];
    
    [HWWebUtils do3GetWithParameters:parametes progress:nil success:^(id response) {
        
        
        NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
        //   [MBProgressHUD hideHUD];
        [self.mainaTableVie.mj_header endRefreshing];
        [self.mainaTableVie.mj_footer endRefreshing];
        
        
        if ([codeStr intValue] == 1) {
            
            
            //     self.topMuArr = [HWjiaoyiModel mj_objectArrayWithKeyValuesArray:response[@"data"][@"top"]];
            
            NSArray *arr = [HWjiaoyuLiebiaoModel mj_objectArrayWithKeyValuesArray:response[@"data"][@"list"]];
            
            
            for (int i = 0 ; i < arr.count; i++) {
                
                [self.listMuArr  addObject:arr[i]];
                
                
                
            }
            
            
            //     self.listMuArr = [HWjiaoyuLiebiaoModel mj_objectArrayWithKeyValuesArray:response[@"data"][@"list"]];
            
            
            
            
            self.p = [NSString stringWithFormat:@"%@",response[@"data"][@"p"]];
            self.max_p =  [NSString stringWithFormat:@"%@",response[@"data"][@"max_p"]];
            
            
            [self.mainaTableVie reloadData];
            [self.maincollectionView reloadData];
            
            
            
            
        } else {
            
            [MBProgressHUD  showSuccess:response[@"message"]];
            
            [self.mainaTableVie reloadData];
            
        }
        NSLog(@"%@",response);
        
        
    } failure:^(NSString *error) {
        
        
        [self.mainaTableVie.mj_header endRefreshing];
        [self.mainaTableVie.mj_footer endRefreshing];
        
        
        [MBProgressHUD  showError:@"查询失败"];
        
        
    }];
    
    
    
    
}








- (void)setupUI {
    
    
    [self addcontronView];
    
    [self addheadeView];
}


- (void)addcontronView {
    
    [self.view  addSubview:self.mainaTableVie];
    
    [_mainaTableVie mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
    }];
    
    self.headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 112+NavBarHeight+58+72+20)];
    self.headerView.backgroundColor = RGB(247, 247, 247);
    self.headerView.backgroundColor  = [UIColor clearColor];
    self.mainaTableVie.tableHeaderView = self.headerView;
    
    
    
    self.guangFanjingxunaView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 58+72+20)];
    self.guangFanjingxunaView.backgroundColor = [UIColor clearColor];
    [self.headerView  addSubview:self.guangFanjingxunaView];
    
    
    
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(20, 25,5,18)];
    
    view1.backgroundColor = RGB(248, 119, 6);
    //    view1.layer.cornerRadius = 10;
    //    view1.layer.masksToBounds = YES;
    //
    [self.guangFanjingxunaView addSubview:view1];
    
    
    
    UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(view1.right+6,20, 200, 28)];
    //     nameLabel.text = fanlilistArr[i];
    //  nameLabel.backgroundColor =  RGB(248, 119, 6);
    nameLabel.backgroundColor = [UIColor clearColor];
    nameLabel.textAlignment = NSTextAlignmentLeft;
    nameLabel.font = [UIFont systemFontOfSize:18];
    nameLabel.textColor = RGB(68, 68, 68);
    //     nameLabel.layer.cornerRadius = 8;
    //     nameLabel.layer.masksToBounds = YES;
    nameLabel.text = @"官方精选";
    nameLabel.text  = [HWjianzhiduiObject keylocalization:@"官方精选"];
    
    [self.guangFanjingxunaView addSubview:nameLabel];
    
}

- (void)addheadeView  {
    
    self.beijingView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 112+NavBarHeight+20)];
    self.beijingView.backgroundColor = [UIColor bm_fulicolorGradientChangeWithSizeView: self.beijingView];
    [self.headerView addSubview: self.beijingView];

    UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(40,10, kScreenW-80, 20)];
    //     nameLabel.text = fanlilistArr[i];
    //  nameLabel.backgroundColor =  RGB(248, 119, 6);
    nameLabel.backgroundColor = [UIColor clearColor];
    nameLabel.textAlignment = NSTextAlignmentCenter;
    nameLabel.font = [UIFont systemFontOfSize:18];
    nameLabel.textColor = RGB(255, 255, 255);
    //     nameLabel.layer.cornerRadius = 8;
    //     nameLabel.layer.masksToBounds = YES;
    nameLabel.text = @"小号交易";
    nameLabel.text = [HWjianzhiduiObject keylocalization:@"小号交易"];
    
    
    
    [self.headerView addSubview:nameLabel];
    
    
    UIButton *fanhuiBut = [UIButton buttonWithType:UIButtonTypeCustom];
    fanhuiBut.frame = CGRectMake(10, 0 , 40, 40);
    fanhuiBut.backgroundColor = [UIColor  clearColor];
    [fanhuiBut setImage:[UIImage imageNamed:@"fanhuijiemianIco"] forState:UIControlStateNormal];
    [fanhuiBut addTarget:self action:@selector(fanhuiButTap) forControlEvents:UIControlEventTouchUpInside];
    
    [self.headerView  addSubview:fanhuiBut];
    
    
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        if (kScreenH >= 812) {
            make.top.mas_equalTo(44);
        }else {
            make.top.mas_equalTo(20);
        }
    }];
    
    [fanhuiBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.centerY.mas_equalTo(nameLabel);
    }];
    
    
    
    
    
    //   NSArray  *listArr = @[@"我要卖号",@"交易记录",@"交易须知",@"客服中心"];
    NSArray  *listArr = @[[HWjianzhiduiObject keylocalization:@"我要卖号"],[HWjianzhiduiObject keylocalization:@"交易记录"],[HWjianzhiduiObject keylocalization:@"交易须知"],[HWjianzhiduiObject keylocalization:@"客服中心"]];
    
    NSArray  *icoArr = @[@"woyaomaihao_maihaoico",@"jiaoyijilu_ico",@"jiaoyixuzhi_ico",@"kefuzhongxin_ico"];
    CGFloat hengjianju = (kScreenW -4*80)/8;
    // CGFloat  shujianju = (166-100)/3;
    
    for (int i = 0 ; i < listArr.count; i++) {
        int shulian = (i*2+2) -1;
        
        
        UIButton *butt  = [UIButton setButtonWithFrame:CGRectMake(i*80+hengjianju*shulian, 112+NavBarHeight-76+10, 80, 76) Title:listArr[i] Image:icoArr[i] Font:13 Color:RGB(255, 255, 255) Target:self Selector:@selector(buttonTap:)];
        
        
        //         UIButton *butt  =  [UIButton createCenterButtonWithFrame:CGRectMake(i*60+hengjianju*shulian, 112+NavBarHeight-76+10, 60, 76) image:icoArr[i] Title:listArr[i] Target:self Selector:@selector(buttonTap:) size:CGSizeMake(50, 50)  font:13];
        
        
        butt.tag = i;
        //   butt.backgroundColor = [UIColor redColor];
        [butt layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleTop imageTitleSpace:6];
        // butt.backgroundColor = [UIColor redColor];
        [self.beijingView addSubview:butt];
        
    }
    
    self.guangFanjingxunaView.frame = CGRectMake(0, self.beijingView.bottom, kScreenW, 58+72);
    self.guangFanjingxunaView.backgroundColor = RGB(247, 247, 247);
    [self addcolocoview];
    
}


- (void)fanhuiButTap {
    
    
    [self.navigationController  popViewControllerAnimated:YES];
    
    
}




- (void)addcolocoview  {
    
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    CGFloat jianju =  (kScreenW - 78*CFLScaleValue*4 -20) / 3;
    layout.minimumLineSpacing = 10;
    layout.minimumInteritemSpacing = 10;
    
    self.maincollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 58, kScreenW,72) collectionViewLayout:layout];
    self.maincollectionView.showsHorizontalScrollIndicator = NO;
    self.maincollectionView.delegate = self;
    self.maincollectionView.dataSource = self;
    //  self.maincollectionView.backgroundColor = RGB(217, 247, 250);
    self.maincollectionView.backgroundColor =  RGB(247, 247, 247);
    //self.maincollectionView.alwaysBounceHorizontal = YES;
    
    
    self.maincollectionView.contentInset = UIEdgeInsetsMake(0, 12, 0, 0);
    //   [self.maincollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView"];  //  一定要设置
    [self.maincollectionView registerClass:[HWjiaoyijiemianCollectionViewCell class] forCellWithReuseIdentifier:@"cellID"];
    //     [self.maincollectionView  registerNib:[UINib nibWithNibName:@"HWShouYouCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"cellID"];
    
    //  [UINib nibWithNibName:@"HWShouYouCollectionViewCell" bundle:nil]
    
    self.maincollectionView.userInteractionEnabled = YES;
    [self.guangFanjingxunaView  addSubview:self.maincollectionView];
    
    
    
    
    
    
    
    
    
}

















- (void)buttonTap:(UIButton *)sender {
    
    NSInteger tag = sender.tag;
    
    if ([[HWLocallyStoredData getLoginUserID] isEqualToString:@""]) {
        HWLoginController  *login = [[HWLoginController alloc]init];
        [self.navigationController pushViewController:login animated:YES];
        return;
        
    }
    
    
    
    if (tag == 0 ) {
        
        
        if ([[HWLocallyStoredData getLoginUserID] isEqualToString:@""]) {
            HWLoginController  *login = [[HWLoginController alloc]init];
            [self.navigationController pushViewController:login animated:YES];
            return;
            
        }
        
        //        HWChenjiaoDonTaiViewController *chengjia = [[HWChenjiaoDonTaiViewController alloc]init];
        //               [self.navigationController pushViewController:chengjia animated:YES];
        //
        HWsXiaoHaoGuanLiViewController *xiaoHao = [[HWsXiaoHaoGuanLiViewController alloc]init];
        [self.navigationController pushViewController:xiaoHao animated:YES];
        
        
        
        
    } else if (tag == 1) {
        
        
        
        HWMyTradingViewController *myTrading  = [[HWMyTradingViewController alloc]init];
        [self.navigationController pushViewController:myTrading animated:YES];
        
        
        //              HWMyTradingViewController *myTrading  = [[HWMyTradingViewController alloc]init];
        //              [self.navigationController pushViewController:myTrading animated:YES];
        //
        
        
    } else if (tag == 2) {
        
        
        //        HWJiaoyixuzhiViewController *jiaoyi = [[HWJiaoyixuzhiViewController alloc]init];
        //        [self.navigationController pushViewController:jiaoyi animated:YES];
        //
        
        NSString *urlStr = [NSString stringWithFormat:@"%@?ct=trade&ac=Notice&app=1&language=%@",[HWOCGlobalConst baseUrl],[HWjianzhiduiObject returnLanguageAcquisition]];
        
        
        XMGWebViewController *webVc = [[XMGWebViewController alloc] init];
        webVc.url = [NSURL URLWithString:urlStr];
        [self.navigationController pushViewController:webVc animated:YES];
        
        
        
    } else {
        
        //        http://star.94php.com/api/app/v3/?ct=app&ac=kefu&token=tFEgIuqFmF6r8ORrvFAeUINU4CN/x0q3KWtWZaJuIjDmL5jgbIRLUbtmtz8XbVuy&t=1608714562&sign=8fcffcf4d80918ecfa6ec0e89afa373f&member=0
        
        
        
        
        
        
        NSString *uid = [HWLocallyStoredData getLoginUserID];
        int t =   [WMUtil  getRandomNumber:101 to:998];
        NSString *tString = [NSString stringWithFormat:@"%ld%d",[WMUtil getTimeSp],t];
        
        //  NSString *gidStr = [NSString stringWithFormat:@"%@",self.gameId];
        NSString *signStr = [NSString stringWithFormat:@"%@%@%@",uid,tString,@"fsd213ewdsadqwe2121213edsad"];
        NSString *signMD5 = [WMUtil md5HexDigest:signStr];
        
        
        NSString *urlStr = [NSString stringWithFormat:@"%@/api/app/v3/?ct=app&ac=kefu&token=%@&t=%@&sign=%@&member=%@&language=%@",[HWOCGlobalConst baseUrl],uid,tString,signMD5,[HWLocallyStoredData getCode],[HWjianzhiduiObject returnLanguageAcquisition]];
        
        
        XMGWebViewController *webVc = [[XMGWebViewController alloc] init];
        webVc.url = [NSURL URLWithString:urlStr];
        [self.navigationController pushViewController:webVc animated:YES];
        
        
    }
    
    
    
    
    
}





- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    
    
    return self.listMuArr.count;
    
    
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *cellID = @"cellId";
    
    HWzuixingjiaoyidanyuanTableViewCell  *cell =  [tableView dequeueReusableCellWithIdentifier:cellID];
    
    if (!cell) {
        cell =  [[NSBundle mainBundle]loadNibNamed:@"HWzuixingjiaoyidanyuanTableViewCell" owner:nil options:nil].firstObject;
        
        
    }
    
    
    cell.selectionStyle =  UITableViewCellSelectionStyleNone;
    HWjiaoyuLiebiaoModel *mode = self.listMuArr[indexPath.row];
    cell.dataModel = mode;
    return  cell;
    
    
    
}




- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 240;
    
    
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    HWjiaoyuLiebiaoModel   *model =   self.listMuArr[indexPath.row];
    HWAccountDetailsViewController *accountDetails = [[HWAccountDetailsViewController alloc]init];
    accountDetails.idStr = model.id;
    [self.navigationController pushViewController:accountDetails animated:YES];
    
    
    
}



- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 58)];
    self.sectionheaderView = view;
    
    view.backgroundColor = RGB(247, 247, 247);
    view.backgroundColor  = RGB(255, 255, 255);
    view.backgroundColor = RGB(247, 247, 247);
    view.userInteractionEnabled = YES;
    
    
//    view.backgroundColor = [UIColor clearColor];
    
    
    
    
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(12, 25,5,18)];
    view1.userInteractionEnabled = YES;
    view1.backgroundColor = RGB(248, 119, 6);
    //    view1.layer.cornerRadius = 10;
    //    view1.layer.masksToBounds = YES;
    //
    [view addSubview:view1];
    
    
    UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(view1.right+6,20, 80, 28)];
    //     nameLabel.text = fanlilistArr[i];
    //  nameLabel.backgroundColor =  RGB(248, 119, 6);
    nameLabel.backgroundColor = [UIColor clearColor];
    nameLabel.textAlignment = NSTextAlignmentLeft;
    nameLabel.font = [UIFont systemFontOfSize:18];
    nameLabel.textColor = RGB(68, 68, 68);
    //     nameLabel.layer.cornerRadius = 8;
    //     nameLabel.layer.masksToBounds = YES;
    nameLabel.text = @"最新发布";
    [view addSubview:nameLabel];
    nameLabel.userInteractionEnabled = YES;
    
    
    self.xianshiLabel = nameLabel;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(nameLabelTap:)];
    
    [nameLabel addGestureRecognizer:tap];
    
    
    
    
    if ([self.sortStr isEqualToString:@"0"]) {
        
        
        NSString *zuixing =  [HWjianzhiduiObject keylocalization:@"最新发布"];
        
        nameLabel.text = @"最新发布";
        nameLabel.text = [HWjianzhiduiObject keylocalization:@"最新发布"];
        nameLabel.text = zuixing;
        
        
        
    } else if ([self.sortStr isEqualToString:@"1"]) {
        
        NSString *zuixing =  [HWjianzhiduiObject keylocalization:@"价格倒序"];
        nameLabel.text = @"价格倒序";
        
        nameLabel.text = [HWjianzhiduiObject keylocalization:@"价格倒序"];
        nameLabel.text = zuixing;
        
        
        
    } else {
        
        NSString *zuixing =  [HWjianzhiduiObject keylocalization:@"价格升序"];
        
        nameLabel.text = @"价格升序";
        nameLabel.text = [HWjianzhiduiObject keylocalization:@"价格升序"];
        nameLabel.text = zuixing;
        
        
    }
    
    
    
    UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectMake(nameLabel.right+4, 20+7, 12, 12)];
    
    imageview.backgroundColor = [UIColor clearColor];
    imageview.image = [UIImage imageNamed:@"xialajiantou"];
    [view addSubview:imageview];
    
    
    
    
    
    
    
    
    
    UITextField *texfeild = [[UITextField alloc]initWithFrame:CGRectMake(12+5+6+80+4+12+5, 18, kScreenW-(12+5+6+80+4+12)-12-5, 35)];
    texfeild.delegate = self;
    texfeild.placeholder = @"请输入关键字进行搜索";
    texfeild.placeholder = [HWjianzhiduiObject keylocalization:@"请输入关键字进行搜索"];
    
    
    texfeild.font = [UIFont systemFontOfSize:14];
    texfeild.backgroundColor = RGB(244, 243, 252);
    
    texfeild.text = self.keyword;
    
    
    
    
    // texfeild.layer.borderColor  = RGB(208, 208, 208).CGColor;
    //   texfeild.layer.borderWidth = 0.5;
    //    UIButton *button =  [UIButton buttonWithType:UIButtonTypeCustom];
    //    button.frame = CGRectMake(0, 0, 30, 30);
    //    [button setImage:[UIImage imageNamed:@"sousukuananniu_ico"] forState:UIControlStateNormal];
    //      [button setImage:[UIImage imageNamed:@"sousukuananniu_ico"] forState:UIControlStateHighlighted];
    
    UIView *sousuoView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 35, 32)];
    UIButton *button =  [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(5, 0, 30, 30);
    [button setImage:[UIImage imageNamed:@"feileidesousu"] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:@"feileidesousu"] forState:UIControlStateHighlighted];
    [sousuoView addSubview:button];
    
    texfeild.leftView = sousuoView;
    
    texfeild.leftViewMode = UITextFieldViewModeAlways;
    texfeild.layer.cornerRadius = 10;
    texfeild.layer.masksToBounds = YES;
    texfeild.backgroundColor = [UIColor whiteColor];
    
    //这里
    //    self.navigationItem.titleView = texfeild;
    
    [view addSubview:texfeild];
    
    
    
    
    
    
    
    
    
    
    
    return  view;
    
    
    
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    
    return 58;
    
    
    
    
}






#pragma  mark -------collectionViewDelegate

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.topMuArr.count;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    HWjiaoyijiemianCollectionViewCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:@"cellID" forIndexPath:indexPath];
    
    // cell.backgroundColor =  RGB(217, 247, 250);
    cell.backgroundColor =  RGB(247, 247, 247);
    cell.dataModel = self.topMuArr[indexPath.row];
    return cell;
    
    
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    return CGSizeMake(148 ,72);
}



- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    DLog(@"点击精品手游单元格");
    
    
    HWjiaoyiModel   *model =   self.topMuArr[indexPath.row];
    HWAccountDetailsViewController *accountDetails = [[HWAccountDetailsViewController alloc]init];
    accountDetails.idStr = model.id;
    [self.navigationController pushViewController:accountDetails animated:YES];
    
}




- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    
    NSLog(@"ushdhhjopijij");
    
    if (textField.text.length > 0 ) {
        self.keyword =  textField.text;
    } else {
        
        self.keyword =  @"";
        
    }
    
    [textField resignFirstResponder];
    
    [self.mainaTableVie.mj_header beginRefreshing];
    
    
    return YES;
    
    
}

-(void)nameLabelTap:(UITapGestureRecognizer *)sender  {
    
    NSLog(@"ygcgyyg");
    
    CGPoint  redCenterInView = [self.mainaTableVie convertPoint:self.sectionheaderView.center toView:self.view];
    
    NSLog(@"%@",NSStringFromCGPoint(redCenterInView));
    NSLog(@"%@",NSStringFromCGPoint(redCenterInView));
    
    [kKeyWindow addSubview:self.sortingView];
    
    
    self.sortingView.whibackvieY =  redCenterInView.y + 26;
    self.sortingView.delagate = self;
    [self.sortingView relayoutTheChildControls];
    
    
}


- (void)HWXuanzePanxuViewZhong:(int )tag {
    
    
    
    self.sortStr = [NSString stringWithFormat:@"%d",tag];
    
    
    [self.mainaTableVie.mj_header beginRefreshing];
    
    
    
    
}





@end
